//
//  WDBusinessCell.m
//  Zhihuijinfu
//
//  Created by 王笛 on 2016/12/22.
//  Copyright © 2016年 王笛. All rights reserved.
//

#import "WDBusinessCell.h"
#import "WDBusiness.h"
#import "WDLinkData.h"

@interface WDBusinessCell ()
@property (weak, nonatomic) IBOutlet UILabel *businessNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *businessTypeLabel;
@property (weak, nonatomic) IBOutlet UILabel *typeLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UILabel *personNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;
@property (weak, nonatomic) IBOutlet UIImageView *iconVIew;
@property (weak, nonatomic) IBOutlet UIImageView *phoneView;
@property (weak, nonatomic) IBOutlet UIButton *phoneBtn;

@end

@implementation WDBusinessCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.layer.cornerRadius = 4;
    self.clipsToBounds = YES;
    
    self.iconVIew.contentMode = UIViewContentModeScaleAspectFit;
    
    self.phoneView.contentMode = UIViewContentModeScaleAspectFit;
    
    [self.phoneBtn setBackgroundImage:[UIImage imageWithColor:[UIColor clearColor]] forState:UIControlStateNormal];
    
    [self.phoneBtn setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithWhite:0.3 alpha:0.3]] forState:UIControlStateHighlighted];
    
}

+ (instancetype)businessCellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"businessCell";
    
    WDBusinessCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (cell == nil) {
        
        cell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] lastObject];
    }
    
    return cell;
}

- (IBAction)callPhoneBtn:(id)sender {
    
    [_delegate callPhoneWithPhoneNumber:self.phoneLabel.text];
    
}

- (void)setBusiness:(WDBusiness *)business
{
    _business = business;
    
    self.businessNameLabel.text = business.name;
    
    self.businessTypeLabel.text = business.status_value;
    
    self.typeLabel.text = business.level_value;
    
    [self layoutIfNeeded];
    
    business.cellH = CGRectGetMaxY(self.phoneBtn.frame);
}

- (void)setLinkData:(WDLinkData *)linkData
{
    _linkData = linkData;
    
    self.personNameLabel.text = linkData.name;
    self.phoneLabel.text = linkData.phone;
}

@end
